<template>
  <div class="playlist-container">
    <div class="top-wrap">
      <div class="img-wrap">
        <img v-lazy="avatarUrl" alt />
      </div>
      <div class="info-wrap">
        <p class="title">{{playlist.name}}</p>
        <div class="author-wrap">
          <img class="avatar" v-lazy="playlist.creator.avatarUrl" v-if="playlist.creator" />
          <span class="name">{{nickname}}</span>
          <span class="time">{{$utils.formatDate(playlist.createTime)}} 创建</span>
        </div>
        <div class="play-wrap">
          <span class="iconfont icon-circle-play"></span>
          <span class="text">播放全部</span>
        </div>
        <div class="tag-wrap">
          <span class="title">标签:</span>
          <ul>
            <li v-for="(item, index) in playlist.tags" :key="index">{{item}}</li>
          </ul>
        </div>
        <div class="desc-wrap">
          <span class="title">简介:</span>
          <span class="desc">{{playlist.description}}</span>
        </div>
      </div>
    </div>
    <el-tabs v-model="activeIndex">
      <el-tab-pane label="歌曲列表" name="1">
        <table class="el-table playlit-table">
          <thead>
            <th></th>
            <th></th>
            <th>音乐标题</th>
            <th>歌手</th>
            <th>专辑</th>
            <th>时长</th>
          </thead>
          <tbody>
            <tr class="el-table__row" v-for="(item, index) in playlist.tracks" :key="item.id">
              <td>{{ index + 1 }}</td>
              <td>
                <div class="img-wrap">
                  <img v-lazy="item.al.picUrl" alt />
                  <span class="iconfont icon-play"></span>
                </div>
              </td>
              <td>
                <div class="song-wrap">
                  <div class="name-wrap">
                    <!-- 名称 -->
                    <span>{{ item.name }}</span>
                    <!-- mv图标 -->
                    <span v-if="item.mvid !== 0" class="iconfont icon-mv"></span>
                  </div>
                </div>
              </td>
              <td>{{item.ar[0].name}}</td>
              <td>{{item.al.name}}</td>
              <td>{{$utils.formatTime(item.dt)}}</td>
            </tr>
          </tbody>
        </table>
      </el-tab-pane>
      <el-tab-pane label="评论(66)" name="2">
        <!-- 精彩评论 -->
        <div class="comment-wrap">
          <p class="title">
            精彩评论
            <span class="number">(666)</span>
          </p>
          <div class="comments-wrap">
            <div class="item">
              <div class="icon-wrap">
                <img src="../../assets/images/avatar.jpg" alt />
              </div>
              <div class="content-wrap">
                <div class="content">
                  <span class="name">爱斯基摩：</span>
                  <span class="comment">谁说的，长大了依旧可爱哈</span>
                </div>
                <div class="re-content">
                  <span class="name">小苹果：</span>
                  <span class="comment">还是小时候比较可爱</span>
                </div>
                <div class="date">2020-02-12 17:26:11</div>
              </div>
            </div>
          </div>
        </div>
        <!-- 最新评论 -->
        <div class="comment-wrap">
          <p class="title">
            最新评论
            <span class="number">(666)</span>
          </p>
          <div class="comments-wrap">
            <div class="item">
              <div class="icon-wrap">
                <img src="../../assets/images/avatar.jpg" alt />
              </div>
              <div class="content-wrap">
                <div class="content">
                  <span class="name">爱斯基摩：</span>
                  <span class="comment">谁说的，长大了依旧可爱哈</span>
                </div>
                <div class="re-content">
                  <span class="name">小苹果：</span>
                  <span class="comment">还是小时候比较可爱</span>
                </div>
                <div class="date">2020-02-12 17:26:11</div>
              </div>
            </div>
            <div class="item">
              <div class="icon-wrap">
                <img src="../../assets/images/avatar.jpg" alt />
              </div>
              <div class="content-wrap">
                <div class="content">
                  <span class="name">爱斯基摩：</span>
                  <span class="comment">谁说的，长大了依旧可爱哈</span>
                </div>
                <div class="re-content">
                  <span class="name">小苹果：</span>
                  <span class="comment">还是小时候比较可爱</span>
                </div>
                <div class="date">2020-02-12 17:26:11</div>
              </div>
            </div>
            <div class="item">
              <div class="icon-wrap">
                <img src="../../assets/images/avatar.jpg" alt />
              </div>
              <div class="content-wrap">
                <div class="content">
                  <span class="name">爱斯基摩：</span>
                  <span class="comment">谁说的，长大了依旧可爱哈</span>
                </div>
                <div class="re-content">
                  <span class="name">小苹果：</span>
                  <span class="comment">还是小时候比较可爱</span>
                </div>
                <div class="date">2020-02-12 17:26:11</div>
              </div>
            </div>
          </div>
        </div>
        <!-- 分页器 -->
        <el-pagination
          @current-change="handleCurrentChange"
          background
          layout="prev, pager, next"
          :total="total"
          :current-page="page"
          :page-size="5"
        ></el-pagination>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import { reqPlaylistDetail, reqSongDetail } from '../../requset/api'
export default {
  name: 'mm',
  data () {
    return {
      id: '', // 歌曲id
      avatarUrl: '',
      nickname: '',
      playlist: '',
      activeIndex: '1',
      // 总条数
      total: 0,
      // 页码
      page: 1
    };
  },
  created () {
    this.id = this.$route.query.id
    this.getPlaylistDetail()
  },
  methods: {
    // 获取歌单详情
    async getPlaylistDetail () {
      const result = await reqPlaylistDetail({
        id: this.id,
        n: 10,
      })
      console.log(result)
      this.avatarUrl = result.playlist.creator.avatarUrl
      this.nickname = result.playlist.creator.nickname
      this.playlist = result.playlist
      // 获取歌曲列表
      // const newSongs = await this._getSongDetail(playlist.trackIds.map((x) => x.id).slice(0, 500))
      // this.songs = newSongs
    },

    // 获取播放列表详情

    // 切换页码
    handleCurrentChange (val) {
      console.log(`当前页: ${val}`)
    }
  }
};
</script>

<style>
</style>
